package com.fromfuture.xuhuidoc.android.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.fromfuture.xuhuidoc.R;
import com.fromfuture.xuhuidoc.android.base.MyWebview;
import com.fromfuture.xuhuidoc.android.commonresouce.MyHtml;

/**
 * 患者详情页面
 * */
public class PatDetailsActivity extends AppCompatActivity {

    private ImageView imageView_back;
    private MyWebview myWebview;

    private String PatGuid;
    private String tag="PatDetailsActivity:-->";
    public String getPatGuid() {
        return PatGuid;
    }
    public void setPatGuid(String patGuid) {
        PatGuid = patGuid;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pat_details);
        init();
    }

    private Handler handler=new Handler();

    private void init(){
        findViewByid();
        receive();
        setMyWebview();
        onclick();

    }
    private void findViewByid(){
        imageView_back= (ImageView) findViewById(R.id.pat_details_back);
        myWebview= (MyWebview) findViewById(R.id.pat_details_webView);
    }
    private void onclick(){
        imageView_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        if (myWebview.canGoBack()){
                            myWebview.goBack();
                        }else {
                            onBackPressed();
                        }
                    }
                });

            }
        });
    }

    private void setMyWebview(){
        myWebview.loadUrl(MyHtml.PATIENT_DETAILS+"?usrGuid="+getPatGuid());
    }

    private void receive(){
        Intent intent=getIntent();
        String patguid=intent.getStringExtra("PatGuid");
        Log.d(tag,patguid);
        setPatGuid(patguid);
    }

}
